package algorithmForInterview40;

/**
 * @author 03010570
 * @date 2020/06/18
 * describe:    LeetCode:141、环形链表 https://leetcode-cn.com/problems/linked-list-cycle/
 */
public class LeetCode_141 {
    public static void main(String[] args) {

    }

    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null || head.next.next == null) {
            return false;
        }
        ListNode fast = head.next;
        ListNode slow = head;
        while (fast != null ) {
            if (fast.val == slow.val) {
                return true;
            }
            fast = fast.next.next;
            slow = slow.next;
        }
        return false;
    }
}
